package com.longcai.piaojia;

import android.app.Dialog;
import android.app.Notification;
import android.content.Context;

import com.longcai.piaojia.db.BaseDB;
import com.longcai.piaojia.dialog.ShowDialog;
import com.tencent.bugly.crashreport.CrashReport;
import com.zcx.helper.app.AppApplication;
import com.zcx.helper.app.AppInit;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.http.Http;

import java.util.concurrent.TimeUnit;

import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;
import cn.sharesdk.framework.ShareSDK;

/**
 * Created by Administrator on 2016/3/14.
 */
@AppInit(name = "PiaoJia", log = false, initialize = true, width = 720, scale = 1f)
public class BaseApplication extends AppApplication {

    public static BasePreferences BasePreferences;

    public static BaseDB baseDB;

    @Override
    public void onCreate() {

        super.onCreate();

        ShareSDK.initSDK(this);

        CrashReport.initCrashReport(getApplicationContext(), "900053079", true);

        baseDB = new BaseDB(this);

        Http.getInstance().setConnectTimeout(30, TimeUnit.SECONDS);

        Http.getInstance().setIsLog(true);

        Http.getInstance().setOnStartEndCreateDialog(new Http.OnStartEndCreateDialog() {

            @Override
            public Dialog onCreate(Context context) {

                return new ShowDialog(context);

            }

            @Override
            public void show(Dialog dialog) {

                dialog.setCanceledOnTouchOutside(false);
                dialog.show();

            }

            @Override
            public void dismiss(Dialog dialog) {

                dialog.dismiss();

            }

        });

        BasePreferences = new BasePreferences(this, "PiaoJia");

        GlideLoader.getInstance().init(R.id.default_id, R.mipmap.goods);

        JPushInterface.setDebugMode(true);

        JPushInterface.init(this);

        BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(this);
//        builder.statusBarDrawable = R.mipmap.push_logo;
        builder.statusBarDrawable = R.mipmap.push_logo_tst;
        //  builder.notificationDefaults=R.mipmap.ic_launcher;

        builder.notificationFlags = Notification.FLAG_AUTO_CANCEL
                | Notification.FLAG_SHOW_LIGHTS;  //设置为自动消失和呼吸灯闪烁
        builder.notificationDefaults = Notification.DEFAULT_SOUND
                | Notification.DEFAULT_VIBRATE
                | Notification.DEFAULT_LIGHTS;  // 设置为铃声、震动、呼吸灯闪烁都要
        JPushInterface.setDefaultPushNotificationBuilder(builder);


/* CustomPushNotificationBuilder builder = new
         CustomPushNotificationBuilder(this,
                R.layout.msg_item,
                R.id.icon,
                R.id.title,
                R.id.text);
        // 指定定制的 Notification Layout
        builder.statusBarDrawable = R.mipmap.push_logo;
        // 指定最顶层状态栏小图标
     //   builder.layoutIconDrawable = R.mipmap.ic_launcher;

        // 指定下拉状态栏时显示的通知图标

        builder.notificationFlags = Notification.FLAG_AUTO_CANCEL
                | Notification.FLAG_SHOW_LIGHTS;  //设置为自动消失和呼吸灯闪烁
        builder.notificationDefaults = Notification.DEFAULT_SOUND
                | Notification.DEFAULT_VIBRATE
                | Notification.DEFAULT_LIGHTS;  // 设置为铃声、震动、呼吸灯闪烁都要
        JPushInterface.setPushNotificationBuilder(2, builder);*/

    }

}
